package com.stagewebserver.webserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stagecommon.common.filter.WordFilter;
import com.stagecommon.common.pojo.RespBean;
import com.stagecommon.common.pojo.WorkComment;
import com.stagewebserver.webserver.mapper.WorkCommentMapper;
import com.stagewebserver.webserver.service.WorkCommentService;
import com.stagecommon.common.vo.WorkCommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yxl
 * @since 2021-11-07
 */
@Service
public class WorkCommentServiceImpl extends ServiceImpl<WorkCommentMapper, WorkComment> implements WorkCommentService {

    @Autowired
    private WorkCommentMapper workCommentMapper;

    @Override
    public List<WorkCommentVo> listCommentByWorkId(Long workId) {
        return workCommentMapper.selectCommentsByWorkId(workId);
    }

    @Override
    public RespBean addComment(WorkComment workComment) {
        workComment.setContent(WordFilter.replaceWords(workComment.getContent()));
        workComment.setCreatedTime(new Timestamp(new Date().getTime()));
        return RespBean.operationSuccess("添加成功",200,workCommentMapper.insert(workComment));
    }
}
